package com.base.controller;

import com.base.comm.CommContent;
import com.base.po.voip.CarParkOrder;
import com.base.service.CarParkOrderService;
import com.base.service.LogsService;
import com.base.utils.IP;
import com.base.utils.Produce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

@Controller
@RequestMapping("/admin")
public class update_CarParkOrder {
	@Autowired
	private LogsService logsService;// log日志
	@Autowired
	private CarParkOrderService carParkOrderService;
	
	String SUCCESS = "success";

	// 更改商户信息
	@RequestMapping(value = "/updateCarParkOrder", method = RequestMethod.POST)
	public void updateCarParkOrder(HttpServletRequest request, HttpServletResponse response,
			@RequestParam(value = "id", required = true) String id,  String expressnumber, 
			Byte deliverystatus, Byte datastatus) throws Exception {
		// 返回参数
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=UTF-8");
	
		CarParkOrder carParkOrder = carParkOrderService.selectByPrimaryKey(id);
		PrintWriter out = response.getWriter();
		
		if (id == null) {
			out.print("浏览器在点击的过程中发现丢失了用户信息，请您刷新重试！");
			return;
		} else {
			if (deliverystatus != null && deliverystatus == 1){
				carParkOrder.setExpressnumber(expressnumber);
				carParkOrder.setStatus((byte)3);
			}
			carParkOrder.setDeliverytime(Produce.getNowDate());
			carParkOrder.setDatastatus(datastatus);
			int code = carParkOrderService.updateByPrimaryKeySelective(carParkOrder);
			String usernamesys = (String) request.getSession().getAttribute("useracc");
			if (code == 1) {
				logsService.insert(CommContent.TYPE_UPDATE, "修改" + carParkOrder.getOrderid() + "发货成功", usernamesys, true,
						IP.getIpAddr(request));
				out.print(SUCCESS);
			} else {
				logsService.insert(CommContent.TYPE_UPDATE, "修改" + carParkOrder.getOrderid() + "发货失败", usernamesys, true,
						IP.getIpAddr(request));
				out.print("更改失败，请您重试");
			}
		}
	}
}
